package org.wisdom.mapper;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.wisdom.entity.Order;

import java.util.List;

@Mapper
public interface OrderMapper {
    @Insert("insert into `order` (order_id, publisher_id, enterprise, address, contacts, contacts_number, transaction_time, `option`, tag, des, photos_url, created_time) values(#{orderId}, #{publisherId}, #{enterprise}, #{address}, #{contacts}, #{contactsNumber}, #{transactionTime}, #{option}, #{tag}, #{des}, #{photosUrl}, #{createdTime})")
    void insertOrder(Order order);

    @Select("select order_id, enterprise, address, contacts, contacts_number, transaction_time, tag, des, photos_url, created_time from `order` where publisher_id = #{id} and `option` = '购买'")
    List<Order> selectSelfBuyOrder(Long id);

    @Select("select order_id, enterprise, address, contacts, contacts_number, transaction_time, tag, des, photos_url, created_time from `order` where publisher_id = #{id} and `option` = '售卖'")
    List<Order> selectSelfSellOrder(Long id);

    @Select("select order_id, publisher_id, enterprise, address, contacts, contacts_number, transaction_time, `option`, tag, des, photos_url, created_time from `order`")
    List<Order> selectPublicAllOrder();

    @Select("select order_id, publisher_id, enterprise, address, contacts, contacts_number, transaction_time, tag, des, photos_url, created_time from `order` where `option` = '购买'")
    List<Order> selectPublicBuyOrder();

    @Select("select order_id, publisher_id, enterprise, address, contacts, contacts_number, transaction_time, tag, des, photos_url, created_time from `order` where `option` = '售卖'")
    List<Order> selectPublicSellOrder();

    @Select("select order_id, publisher_id, enterprise, address, contacts, contacts_number, transaction_time, `option`, tag, des, photos_url, created_time from `order` where order_id = #{id}")
    Order selectOrder(Long id);
}
